package com.apigen.platform.dto;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
import java.util.List;
import java.util.Map;

/**
 * 代码生成请求DTO
 *
 * @author API Generator Platform
 * @since 2024-09-24
 */
@Data
@Schema(description = "代码生成配置参数")
public class CodeGenerationRequest {

    @NotNull(message = "项目ID不能为空")
    @Schema(description = "项目ID", example = "1")
    private Long projectId;

    @NotBlank(message = "项目名称不能为空")
    @Schema(description = "项目名称", example = "user-management-api")
    private String projectName;

    @NotBlank(message = "项目编码不能为空")
    @Pattern(regexp = "^[a-z][a-z0-9-]*[a-z0-9]$", message = "项目编码只能包含小写字母、数字和连字符，且必须以字母开头")
    @Schema(description = "项目编码", example = "user-mgmt-api")
    private String projectCode;

    @Schema(description = "项目描述", example = "用户管理系统API")
    private String description;

    @NotBlank(message = "框架类型不能为空")
    @Schema(description = "框架类型", example = "SPRING_BOOT", allowableValues = {"SPRING_BOOT", "EXPRESS", "FASTAPI", "NESTJS"})
    private String frameworkType;

    @NotBlank(message = "包名不能为空")
    @Pattern(regexp = "^[a-z][a-z0-9]*(\\.([a-z][a-z0-9]*))*$", message = "包名格式不正确")
    @Schema(description = "包名", example = "com.example.usermgmt")
    private String packageName;

    @Schema(description = "作者", example = "API Generator")
    private String author = "API Generator";

    @Schema(description = "版本号", example = "1.0.0")
    private String version = "1.0.0";

    @Schema(description = "数据库类型", example = "MYSQL", allowableValues = {"MYSQL", "POSTGRESQL", "ORACLE", "SQL_SERVER"})
    private String databaseType = "MYSQL";

    @Schema(description = "模板ID", example = "2")
    private Long templateId;

    @Schema(description = "要生成的表ID列表")
    private List<Long> tableIds;

    @Schema(description = "生成配置")
    private GenerationConfig config;

    @Data
    @Schema(description = "代码生成配置")
    public static class GenerationConfig {

        @Schema(description = "生成Entity", example = "true")
        private Boolean generateEntity = true;

        @Schema(description = "生成DTO", example = "true")
        private Boolean generateDto = true;

        @Schema(description = "生成VO", example = "true")
        private Boolean generateVo = true;

        @Schema(description = "生成Mapper", example = "true")
        private Boolean generateMapper = true;

        @Schema(description = "生成Service", example = "true")
        private Boolean generateService = true;

        @Schema(description = "生成Controller", example = "true")
        private Boolean generateController = true;

        @Schema(description = "生成配置文件", example = "true")
        private Boolean generateConfig = true;

        @Schema(description = "生成文档", example = "true")
        private Boolean generateDoc = true;

        @Schema(description = "生成测试文件", example = "false")
        private Boolean generateTest = false;

        @Schema(description = "生成Docker文件", example = "true")
        private Boolean generateDocker = true;

        @Schema(description = "使用Lombok", example = "true")
        private Boolean useLombok = true;

        @Schema(description = "使用Swagger", example = "true")
        private Boolean useSwagger = true;

        @Schema(description = "启用分页", example = "true")
        private Boolean enablePagination = true;

        @Schema(description = "启用缓存", example = "true")
        private Boolean enableCache = true;

        @Schema(description = "启用日志", example = "true")
        private Boolean enableLogging = true;

        @Schema(description = "启用事务", example = "true")
        private Boolean enableTransaction = true;

        @Schema(description = "启用验证", example = "true")
        private Boolean enableValidation = true;

        @Schema(description = "数据库配置")
        private DatabaseConfig database;

        @Schema(description = "Redis配置")
        private RedisConfig redis;

        @Schema(description = "JWT配置")
        private JwtConfig jwt;

        @Schema(description = "自定义配置")
        private Map<String, Object> customConfig;
    }

    @Data
    @Schema(description = "数据库配置")
    public static class DatabaseConfig {

        @Schema(description = "数据库主机", example = "localhost")
        private String host = "localhost";

        @Schema(description = "数据库端口", example = "3306")
        private Integer port = 3306;

        @Schema(description = "数据库名", example = "user_management")
        private String database;

        @Schema(description = "用户名", example = "root")
        private String username = "root";

        @Schema(description = "密码")
        private String password;

        @Schema(description = "字符集", example = "utf8mb4")
        private String charset = "utf8mb4";
    }

    @Data
    @Schema(description = "Redis配置")
    public static class RedisConfig {

        @Schema(description = "Redis主机", example = "localhost")
        private String host = "localhost";

        @Schema(description = "Redis端口", example = "6379")
        private Integer port = 6379;

        @Schema(description = "Redis密码")
        private String password;

        @Schema(description = "数据库索引", example = "0")
        private Integer database = 0;

        @Schema(description = "连接超时", example = "5000")
        private Integer timeout = 5000;
    }

    @Data
    @Schema(description = "JWT配置")
    public static class JwtConfig {

        @Schema(description = "JWT密钥")
        private String secret;

        @Schema(description = "访问令牌过期时间(秒)", example = "7200")
        private Long expiration = 7200L;

        @Schema(description = "刷新令牌过期时间(秒)", example = "604800")
        private Long refreshExpiration = 604800L;
    }
}











